//
//  BaseViewController.m
//  HaiKangDemo
//
//  Created by 崔 on 16/10/3.
//  Copyright © 2016年 崔. All rights reserved.
//

#import "BaseViewController.h"
#import "ALSConstNSString.h"
@interface BaseViewController () <UIGestureRecognizerDelegate>

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    UINavigationBar *bar = [UINavigationBar appearance];
    
    NSMutableDictionary *att = [NSMutableDictionary dictionary];
    
    att[NSForegroundColorAttributeName] = [UIColor whiteColor];
    
    [bar setTitleTextAttributes:att];
    
    //设置背景
//    UIImageView *backView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"backgroung"]];
//    backView.frame = [UIScreen mainScreen].bounds;
//    
//    for (UIViewController *vc in self.childViewControllers) {
//        NSLog(@"---%@",vc);
//        [vc.view insertSubview:backView atIndex:0];
//    }
    [bar setBackgroundImage:[UIImage imageNamed:@"点击栏"] forBarMetrics:UIBarMetricsDefault];
    
    //当自定义过导航栏的返回按钮时,右滑手势失效
    self.interactivePopGestureRecognizer.delegate = self;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(als3DTouch) name:ALS3DTouchBeginActionNotification object:nil];
    
}

- (void)als3DTouch {
    [self popToRootViewControllerAnimated:NO];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    //push 时隐藏tabBar
    [viewController setHidesBottomBarWhenPushed:YES];
    
    [super pushViewController:viewController animated:YES];
    
}
#pragma  mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    if (self.childViewControllers.count == 1) {
        
        return NO;
    }
    
    return YES;
//    return self.childViewControllers.count >1; //也可以这么写
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
